package com.lin.chapter34;

import java.util.ArrayList;
import java.util.List;

public class CommandVo {
    public final static String DIVIDE_FLAG = " ";
    public final static String PREFIX = "-";
    private String commandName = "";

    private List<String> paramList = new ArrayList<>();
    private List<String> dataList = new ArrayList<>();

    public CommandVo(String commandStr){
        if (commandStr != null && commandStr.length() != 0){
            String[] complexStr = commandStr.split(CommandVo.DIVIDE_FLAG);
            this.commandName = complexStr[0];
            for (int i = 0; i < complexStr.length; i++) {
                String str = complexStr[i];
                if (str.indexOf(CommandVo.PREFIX) == 0){
                    this.paramList.add(str.replace(CommandVo.PREFIX, "").trim());
                }else {
                    this.dataList.add(str.trim());
                }
            }
        }else {
            System.out.println("命令解析失败，必须传递一个命令才能执行");
        }
    }

    public String getCommandName(){
        return this.commandName;
    }

    public List<String> getParamList() {
        if (this.paramList.size() == 0){
            this.paramList.add("");
        }
        return paramList;
    }

    public List<String> getDataList() {
        return dataList;
    }


}
